/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef CANBUSRFID_H
#define CANBUSRFID_H

#include <qmap.h>

#include "ecattype.h"
#include "canbusrfidconfig.h"
#include "canbusdevicedriver.h"

//class CanbusRfidConfig;
//class CanbusDeviceDriver;
/**
 * @brief The CanbusRfid class can rfid接口
 */
class CanbusRfid
{
public:
    CanbusRfid(QString configFileNameIn,int aliasIn, int busNumberIn, int deviceIdIn, CanbusDeviceDriver *canbusDriverIn);
    ~CanbusRfid();

public:
    int startPdoMode();
    int getAlias();
    int sendDataRequestCommand();
    int processDataFrame(unsigned char cardValueOut[8],bool &isCardDetectedOut);
    /**
     * @brief getCurrentTagData  获取读卡数据接口
     * @param deviceId           RFID读卡器设备地址
     * @param valueOut           RFID卡内数据
     * @param readCardTime       当前数据的读卡时间
     * @return    success: 1  failed: -1  (卡片未在读取范围内: return-0, valueOut=0)
     */
    int getCurrentTagDataFromBuffer(QVector<unsigned char> &cardValueOut,bool &isCardDetectedOut);

    int writeTagDataUndirect(QVector<unsigned char> cardValueIn);

    /**
     * @brief isInitialOkStatus
     * @return
     */
    bool isInitialOkStatus();

    /**
     * @brief setSensorDeviceId
     * @param primaryIdIn
     * @param targetIdIn
     * @return
     */
    int setSensorDeviceId(int primaryIdIn, int targetIdIn, int busNumberIn);

    int updateData();

    int getDeviceAddressInfo(int& aliasOut, int& busNumberOut, int& deviceIdOut);
    int getVendorId();
    int downloadSdoConfig();

private:
    int processDataFrame_XingSong(unsigned char cardValueOut[8],bool &isCardDetectedOut);
    int processDataFrame_YuanBen(unsigned char cardValueOut[8],bool &isCardDetectedOut);
    int writeRfidCardData(QVector<unsigned char> cardValueIn);
    int writeRfidCardData_XingSong(QVector<unsigned char> cardValueIn);
    int writeRfidCardData_YuanBen(QVector<unsigned char> cardValueIn);
    int getCurrentTagData(unsigned char cardValueOut[8],bool &isCardDetectedOut);

protected:

    int initial(QString fileName);

private:

    unsigned char cardValue[8];
    bool isCardDetected;

    CanbusRfidConfig* driverConfig;
    int alias;
    int busNumber;
    int deviceId;
    bool isInitialedOk;

    RegConfig regConfig;
    RegAddressInfo regAdd;
    E_VENDOR_ID vendorId;

    CanbusDeviceDriver *canbusDriver;

    bool writeCardCommandFlag;
    unsigned char cardValue_command[8];
    QVector<SdoConfig> sdoConfigList;

};

#endif // CANBUSRFID_H
